import wx
import os

from utils import tracer
from uiManager import UIManager
from gui.mdiFrame import MDIFrame

class StatusbarManager(UIManager):  
  def __init__(self, name):
    UIManager.__init__(self, name)
    self._statusBar = None

  def attach(self, uiParent):
    if uiParent is None:
      return

    assert type(uiParent) is MDIFrame
    self._uiParent = uiParent

    tracer.writeln('%s attaching ...' % self.getName())

    self._statusBar = wx.StatusBar(self._uiParent)
    self._uiParent.SetStatusBar(self._statusBar)

    tracer.writeln(' Done%s' % os.linesep)

  def detach(self):
    if self._uiParent is None:
      return

    self._uiParent.SetStatusBar(None)

  def createMenus(self, uiParent):
    if uiParent is None:
      return None

    menus = []

    # create file menu
    view_menu = wx.Menu()

    view_menu_statusbars_menu = wx.Menu()

    view_menu_status_bar = view_menu_statusbars_menu.AppendCheckItem(-1, 'StatusBar')
    view_menu_status_bar.Check(self._statusBar.IsShown())
    uiParent.Bind(wx.EVT_MENU, self.onPaneMenuClicked, view_menu_status_bar)

    view_menu.AppendMenu(-1, 'Statusbars', view_menu_statusbars_menu)

    menus.append(('&View', view_menu))

    return menus

  def onPaneMenuClicked(self, evt):
    if self._uiParent is None:
      evt.Skip()
    self._statusBar.Show(evt.IsChecked())